/*
 * 作者: 侯晓宇
 * 时间: 2017-02-16 
 * 说明：
 * Copyright (c) 2016-2017 中研沃兮
 */
define(function(require) {
	
	var appInfo = require('app/AppInfo');
	var c = require('app/utils/CommonUtils');
	var UserInfoUtils = require('app/utils/UserInfoUtils');
	var ctl = {};
	var param = api.pageParam;
	var playerItem = {};
	var mediaPlayer = api.require('aliyunLive');
	var EventUtils = require('app/utils/EventUtils');
	
	var splitPagesArr = function(pages){
		var arr = [];
		for(var i = 0; i< pages.length; i++){
			if(pages[i].type == "live" || pages[i].type== "video" ){
//				arr.push(pages[i].publishurl);
				arr.push(pages[i].pageurl);
			}
		}
		return arr;
	}
	
	ctl.init = function(pages){
		var arr = splitPagesArr(pages);
		var url = arr[0];
		var coverurl = "widget://res/placeholder/black.png"
		var live_w = api.frameWidth;
		var live_h = api.frameHeight;

		 $("#a1").css({
	    	"width":live_w+"px",
	    	"height": live_h + "px"
	    });
		var flashvars={
			f:url,
			c:0, //	=0：调用ckplayer.js
			p:0,
			h:3,
			lv:1,
			i:coverurl
			};
		
		var video=[url];
		var support=['all'];
    
		var params={bgcolor:'#FFF',allowFullScreen:true,allowScriptAccess:'always',wmode:'transparent'};
		CKobject.embedHTML5('a1','ckplayer_a1',live_w,live_h,video,flashvars,support);
	    
		
		
		
		
//		var obj = api.require('aplayer');
//obj.play({
//  rect:
//  {    x: 0,
//      y : 0,
//     w: api.winWidth,
//				h: parseInt(api.winWidth * 9 / 16)
//  },
//  fixedOn: api.frameName,
//  title: '',
//  url: playerurl,//'http://resource.apicloud.com/video/apicloud3.mp4',
//  defaultBtn: true,
//  enableFull: false
//}, function(ret, err) {
//
//});
//		mediaPlayer.init({
//			rect: {
//				x: 0,
//				y: 0,
//				w: api.winWidth,
//				h: parseInt(api.winWidth * 9 / 16)
//			},
//			fixedOn: api.frameName,
//			accessKeyId: 'LTAIbkVTJcwHwkRa',
//			accessKeySecret: 'RczGrSBSsrahL8k1c9yD3YzQ3kKlMw',
//			businessId: 'luyanplayer',
//		}, function(ret, err) {
//			if (ret) {
//				mediaPlayer.prepareToPlay({
//					url: playerurl
//				}, function(ret, err) {
//					if (ret && ret.status) {
////					>>>>>>>>>>>>>>>>>>>>>:{"id":16,"uuid":"0207b918-684c-4ebb-954a-dcc6cb121112","creatoruuid":"9163edd3-2baa-4803-a683-dc282ef7fd4b","name":"0419期机械工程专业","des":"徐志刚教授，山东大学机械工程学院，高效洁净机械制造教育部重点实验室主任","time":1461056857000,"createtime":null,"endtime":null,"type":"3","thumburl":"http://7xstaf.com2.z0.glb.qiniucdn.com/logo%2Fhjs%2Fjixiegongcheng.jpg","coverurl":"http://7xszfr.com2.z0.glb.qiniucdn.com/image%2F0419%2Fhjs%2Fcover.jpg","livecoverurl":"http://7xstaf.com2.z0.glb.qiniucdn.com/logo%2Fhjs%2Fjixiegongcheng.jpg","fee":0,"roomchairs":"徐志刚教授|山东大学","roomtimestr":null,"attendeecount":3771,"orguuid":"6b329a9e-febb-11e5-86aa-5e5517507777","doortemplate":"template_gaokao","maxconcurrent":2,"tab2Name":null,"tab2Htmlsegment":null,"tab3Name":null,"tab3Htmlsegment":null,"tab4Name":null,"tab4Htmlsegment":null,"pwd":null,"roomType":"1","liveType":"2","likecount":0,"pages":[{"id":68,"pageurl":"http://7xsvsj.com2.z0.glb.qiniucdn.com/image/0419/page1.jpg","lectureid":"f2f612d9-d38e-4f71-a00e-8a30d8789789","num":0,"time":null,"creatorid":null,"type":"img","thumburl":null,"publishurl":null,"publishid":null},{"id":69,"pageurl":"http://7xsvsj.com2.z0.glb.qiniucdn.com/image/0419/%E5%B9%BB%E7%81%AF%E7%89%872.JPG","lectureid":"f2f612d9-d38e-4f71-a00e-8a30d8789789","num":1,"time":null,"creatorid":null,"type":"img","thumburl":null,"publishurl":null,"publishid":null},{"id":70,"pageurl":"http://7xsvsj.com2.z0.glb.qiniucdn.com/image/0419/%E5%B9%BB%E7%81%AF%E7%89%873.JPG","lectureid":"f2f612d9-d38e-4f71-a00e-8a30d8789789","num":2,"time":null,"creatorid":null,"type":"img","thumburl":null,"publishurl":null,"publishid":null},{"id":71,"pageurl":"http://7xsvsj.com2.z0.glb.qiniucdn.com/image/0419/%E5%B9%BB%E7%81%AF%E7%89%874.JPG","lectureid":"f2f612d9-d38e-4f71-a00e-8a30d8789789","num":3,"time":null,"creatorid":null,"type":"img","thumburl":null,"publishurl":null,"publishid":null},{"id":72,"pageurl":"http://7xsvsj.com2.z0.glb.qiniucdn.com/image/0419/%E5%B9%BB%E7%81%AF%E7%89%875.JPG","lectureid":"f2f612d9-d38e-4f71-a00e-8a30d8789789","num":4,"time":null,"creatorid":null,"type":"img","thumburl":null,"publishurl":null,"publishid":null},{"id":73,"pageurl":"http://7xsvsj.com2.z0.glb.qiniucdn.com/image/0419/%E5%B9%BB%E7%81%AF%E7%89%876.JPG","lectureid":"f2f612d9-d38e-4f71-a00e-8a30d8789789","num":5,"time":null,"creatorid":null,"type":"img","thumburl":null,"publishurl":null,"publishid":null},{"id":74,"pageurl":"http://7xsvsj.com2.z0.glb.qiniucdn.com/image/0419/%E5%B9%BB%E7%81%AF%E7%89%877.JPG","lectureid":"f2f612d9-d38e-4f71-a00e-8a30d8789789","num":6,"time":null,"creatorid":null,"type":"img","thumburl":null,"publishurl":null,"publishid":null},{"id":75,"pageurl":"http://7xsvsj.com2.z0.glb.qiniucdn.com/image/0419/%E5%B9%BB%E7%81%AF%E7%89%878.JPG","lectureid":"f2f612d9-d38e-4f71-a00e-8a30d8789789","num":7,"time":null,"creatorid":null,"type":"img","thumburl":null,"publishurl":null,"publishid":null},{"id":76,"pageurl":"http://7xsvsj.com2.z0.glb.qiniucdn.com/image/0419/%E5%B9%BB%E7%81%AF%E7%89%879.JPG","lectureid":"f2f612d9-d38e-4f71-a00e-8a30d8789789","num":8,"time":null,"creatorid":null,"type":"img","thumburl":null,"publishurl":null,"publishid":null},{"id":77,"pageurl":"http://7xsvsj.com2.z0.glb.qiniucdn.com/image/0419/%E5%B9%BB%E7%81%AF%E7%89%8710.JPG","lectureid":"f2f612d9-d38e-4f71-a00e-8a30d8789789","num":9,"time":null,"creatorid":null,"type":"img","thumburl":null,"publishurl":null,"publishid":null},{"id":78,"pageurl":"http://7xsvsj.com2.z0.glb.qiniucdn.com/image/0419/%E5%B9%BB%E7%81%AF%E7%89%8711.JPG","lectureid":"f2f612d9-d38e-4f71-a00e-8a30d8789789","num":10,"time":null,"creatorid":null,"type":"img","thumburl":null,"publishurl":null,"publishid":null},{"id":79,"pageurl":"http://7xsvsj.com2.z0.glb.qiniucdn.com/image/0419/%E5%B9%BB%E7%81%AF%E7%89%8712.JPG","lectureid":"f2f612d9-d38e-4f71-a00e-8a30d8789789","num":11,"time":null,"creatorid":null,"type":"img","thumburl":null,"publishurl":null,"publishid":null},{"id":80,"pageurl":"http://7xsvsj.com2.z0.glb.qiniucdn.com/image/0419/%E5%B9%BB%E7%81%AF%E7%89%8713.JPG","lectureid":"f2f612d9-d38e-4f71-a00e-8a30d8789789","num":12,"time":null,"creatorid":null,"type":"img","thumburl":null,"publishurl":null,"publishid":null},{"id":81,"pageurl":"http://7xsvsj.com2.z0.glb.qiniucdn.com/image/0419/%E5%B9%BB%E7%81%AF%E7%89%8714.JPG","lectureid":"f2f612d9-d38e-4f71-a00e-8a30d8789789","num":13,"time":null,"creatorid":null,"type":"img","thumburl":null,"publishurl":null,"publishid":null},{"id":82,"pageurl":"http://7xsvsj.com2.z0.glb.qiniucdn.com/image/0419/%E5%B9%BB%E7%81%AF%E7%89%8715.JPG","lectureid":"f2f612d9-d38e-4f71-a00e-8a30d8789789","num":14,"time":null,"creatorid":null,"type":"img","thumburl":null,"publishurl":null,"publishid":null},{"id":83,"pageurl":"http://7xsvsj.com2.z0.glb.qiniucdn.com/image/0419/%E5%B9%BB%E7%81%AF%E7%89%8716.JPG","lectureid":"f2f612d9-d38e-4f71-a00e-8a30d8789789","num":15,"time":null,"creatorid":null,"type":"img","thumburl":null,"publishurl":null,"publishid":null},{"id":84,"pageurl":"http://7xsvsj.com2.z0.glb.qiniucdn.com/image/0419/%E5%B9%BB%E7%81%AF%E7%89%8717.JPG","lectureid":"f2f612d9-d38e-4f71-a00e-8a30d8789789","num":16,"time":null,"creatorid":null,"type":"img","thumburl":null,"publishurl":null,"publishid":null},{"id":85,"pageurl":"http://7xsvsj.com2.z0.glb.qiniucdn.com/image/0419/%E5%B9%BB%E7%81%AF%E7%89%8718.JPG","lectureid":"f2f612d9-d38e-4f71-a00e-8a30d8789789","num":17,"time":null,"creatorid":null,"type":"img","thumburl":null,"publishurl":null,"publishid":null},{"id":86,"pageurl":"http://7xsvsj.com2.z0.glb.qiniucdn.com/image/0419/%E5%B9%BB%E7%81%AF%E7%89%8719.JPG","lectureid":"f2f612d9-d38e-4f71-a00e-8a30d8789789","num":18,"time":null,"creatorid":null,"type":"img","thumburl":null,"publishurl":null,"publishid":null},{"id":87,"pageurl":"http://7xsvsj.com2.z0.glb.qiniucdn.com/image/0419/%E5%B9%BB%E7%81%AF%E7%89%8720.JPG","lectureid":"f2f612d9-d38e-4f71-a00e-8a30d8789789","num":19,"time":null,"creatorid":null,"type":"img","thumburl":null,"publishurl":null,"publishid":null},{"id":88,"pageurl":"http://7xsvsj.com2.z0.glb.qiniucdn.com/image/0419/%E5%B9%BB%E7%81%AF%E7%89%8721.JPG","lectureid":"f2f612d9-d38e-4f71-a00e-8a30d8789789","num":20,"time":null,"creatorid":null,"type":"img","thumburl":null,"publishurl":null,"publishid":null},{"id":89,"pageurl":"http://7xsvsj.com2.z0.glb.qiniucdn.com/image/0419/%E5%B9%BB%E7%81%AF%E7%89%8722.JPG","lectureid":"f2f612d9-d38e-4f71-a00e-8a30d8789789","num":21,"time":null,"creatorid":null,"type":"img","thumburl":null,"publishurl":null,"publishid":null},{"id":90,"pageurl":"http://7xsvsj.com2.z0.glb.qiniucdn.com/image/0419/%E5%B9%BB%E7%81%AF%E7%89%8723.JPG","lectureid":"f2f612d9-d38e-4f71-a00e-8a30d8789789","num":22,"time":null,"creatorid":null,"type":"img","thumburl":null,"publishurl":null,"publishid":null},{"id":91,"pageurl":"http://7xsvsj.com2.z0.glb.qiniucdn.com/image/0419/%E5%B9%BB%E7%81%AF%E7%89%8724.JPG","lectureid":"f2f612d9-d38e-4f71-a00e-8a30d8789789","num":23,"time":null,"creatorid":null,"type":"img","thumburl":null,"publishurl":null,"publishid":null},{"id":92,"pageurl":"http://7xsvsj.com2.z0.glb.qiniucdn.com/image/0419/%E5%B9%BB%E7%81%AF%E7%89%8725.JPG","lectureid":"f2f612d9-d38e-4f71-a00e-8a30d8789789","num":24,"time":null,"creatorid":null,"type":"img","thumburl":null,"publishurl":null,"publishid":null},{"id":93,"pageurl":"http://7xsvsj.com2.z0.glb.qiniucdn.com/image/0419/%E5%B9%BB%E7%81%AF%E7%89%8726.JPG","lectureid":"f2f612d9-d38e-4f71-a00e-8a30d8789789","num":25,"time":null,"creatorid":null,"type":"img","thumburl":null,"publishurl":null,"publishid":null},{"id":94,"pageurl":"http://7xsvsj.com2.z0.glb.qiniucdn.com/image/0419/%E5%B9%BB%E7%81%AF%E7%89%8727.JPG","lectureid":"f2f612d9-d38e-4f71-a00e-8a30d8789789","num":26,"time":null,"creatorid":null,"type":"img","thumburl":null,"publishurl":null,"publishid":null},{"id":95,"pageurl":"http://7xsvsj.com2.z0.glb.qiniucdn.com/image/0419/%E5%B9%BB%E7%81%AF%E7%89%8728.JPG","lectureid":"f2f612d9-d38e-4f71-a00e-8a30d8789789","num":27,"time":null,"creatorid":null,"type":"img","thumburl":null,"publishurl":null,"publishid":null},{"id":96,"pageurl":"http://7xsvsj.com2.z0.glb.qiniucdn.com/image/0419/%E5%B9%BB%E7%81%AF%E7%89%8729.JPG","lectureid":"f2f612d9-d38e-4f71-a00e-8a30d8789789","num":28,"time":null,"creatorid":null,"type":"img","thumburl":null,"publishurl":null,"publishid":null},{"id":97,"pageurl":"http://7xsvsj.com2.z0.glb.qiniucdn.com/image/0419/%E5%B9%BB%E7%81%AF%E7%89%8730.JPG","lectureid":"f2f612d9-d38e-4f71-a00e-8a30d8789789","num":29,"time":null,"creatorid":null,"type":"img","thumburl":null,"publishurl":null,"publishid":null},{"id":98,"pageurl":"http://7xsvsj.com2.z0.glb.qiniucdn.com/image/0419/%E5%B9%BB%E7%81%AF%E7%89%8731.JPG","lectureid":"f2f612d9-d38e-4f71-a00e-8a30d8789789","num":30,"time":null,"creatorid":null,"type":"img","thumburl":null,"publishurl":null,"publishid":null},{"id":99,"pageurl":"http://7xsvsj.com2.z0.glb.qiniucdn.com/image/0419/%E5%B9%BB%E7%81%AF%E7%89%8732.JPG","lectureid":"f2f612d9-d38e-4f71-a00e-8a30d8789789","num":31,"time":null,"creatorid":null,"type":"img","thumburl":null,"publishurl":null,"publishid":null},{"id":100,"pageurl":"http://7xsvsj.com2.z0.glb.qiniucdn.com/image/0419/%E5%B9%BB%E7%81%AF%E7%89%8733.JPG","lectureid":"f2f612d9-d38e-4f71-a00e-8a30d8789789","num":32,"time":null,"creatorid":null,"type":"img","thumburl":null,"publishurl":null,"publishid":null},{"id":101,"pageurl":"http://7xsvsj.com2.z0.glb.qiniucdn.com/image/0419/%E5%B9%BB%E7%81%AF%E7%89%8734.JPG","lectureid":"f2f612d9-d38e-4f71-a00e-8a30d8789789","num":33,"time":null,"creatorid":null,"type":"img","thumburl":null,"publishurl":null,"publishid":null},{"id":102,"pageurl":"http://7xsvsj.com2.z0.glb.qiniucdn.com/image/0419/%E5%B9%BB%E7%81%AF%E7%89%8735.JPG","lectureid":"f2f612d9-d38e-4f71-a00e-8a30d8789789","num":34,"time":null,"creatorid":null,"type":"img","thumburl":null,"publishurl":null,"publishid":null},{"id":103,"pageurl":"http://7xsvsj.com2.z0.glb.qiniucdn.com/image/0419/%E5%B9%BB%E7%81%AF%E7%89%8736.JPG","lectureid":"f2f612d9-d38e-4f71-a00e-8a30d8789789","num":35,"time":null,"creatorid":null,"type":"img","thumburl":null,"publishurl":null,"publishid":null},{"id":104,"pageurl":"http://7xsvsj.com2.z0.glb.qiniucdn.com/image/0419/%E5%B9%BB%E7%81%AF%E7%89%8737.JPG","lectureid":"f2f612d9-d38e-4f71-a00e-8a30d8789789","num":36,"time":null,"creatorid":null,"type":"img","thumburl":null,"publishurl":null,"publishid":null},{"id":105,"pageurl":"http://7xsvsj.com2.z0.glb.qiniucdn.com/image/0419/%E5%B9%BB%E7%81%AF%E7%89%8738.JPG","lectureid":"f2f612d9-d38e-4f71-a00e-8a30d8789789","num":37,"time":null,"creatorid":null,"type":"img","thumburl":null,"publishurl":null,"publishid":null},{"id":106,"pageurl":"http://7xsvsj.com2.z0.glb.qiniucdn.com/image/0419/%E5%B9%BB%E7%81%AF%E7%89%8739.JPG","lectureid":"f2f612d9-d38e-4f71-a00e-8a30d8789789","num":38,"time":null,"creatorid":null,"type":"img","thumburl":null,"publishurl":null,"publishid":null},{"id":107,"pageurl":"http://7xsvsj.com2.z0.glb.qiniucdn.com/image/0419/%E5%B9%BB%E7%81%AF%E7%89%8740.JPG","lectureid":"f2f612d9-d38e-4f71-a00e-8a30d8789789","num":39,"time":null,"creatorid":null,"type":"img","thumburl":null,"publishurl":null,"publishid":null}],"lecture":{"id":13,"uuid":"f2f612d9-d38e-4f71-a00e-8a30d8789789","name":"高考专业微讲堂","des":null,"creatorid":null,"time":null,"roomid":"0207b918-684c-4ebb-954a-dcc6cb121112","ratio":"0.5625","lecStart":null,"lecEnd":null,"downloaded":"0","code":"1","ppturl":null}} at CommonUtils.js : 97
//						var creatoruuid = param.creatoruuid;
//						var userid = UserInfoUtils.getLoginedUser().userid;
//						if(userid == creatoruuid && param.liveType =="1"){
//						
//							var header_h = c.remToPx(2.25);
//
//							api.openFrame({
//							    name: 'RoomPlayerMaskFrm',
//							    url: './RoomPlayerMaskFrm.html',
//							    rect: {
//								    x:0,
//								    y:header_h,
//								    w:api.frameWidth,
//								    h:api.frameHeight - header_h
//							    },
//							    bgColor: 'rgba(0,0,0,0)'
//						    });
//							
//						}else{
//							mediaPlayer.play();
//						}
//						
//						
//					}
//	
//				});
//			}
//		});
//		
//		
//		
		
		
		
		
	}
	
	EventUtils.listen(api.winName,'startplay',true,function(data){
		mediaPlayer.play();
	});
	return ctl;
});